<?php
include_once ("../Login/databaseconnection.php");
$Lab_Type=$_POST['Lab_Type'];
$New_Lab_Type=$_POST['New_Lab_Type'];
$Lab_Category=$_POST['Lab_Category'];
$New_Lab_Category=$_POST['New_Lab_Category'];
$Special_Projects=$_POST['Special_Projects'];
$S_Pro="";
$S_Proje="";
for($i=0;$i<sizeof($Special_Projects);$i++)
  {
  if($i==0)
  {
   if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro="other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro="other_".$spe_other;
  }
  }
  else
  {
  $S_Pro=$Special_Projects[0];
  }
  }
   else
  {
    if($Special_Projects[$i]=="Others(P1.specify)")
  {
  $S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro=$S_Pro.",other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro=$S_Pro.",other_".$spe_other;
  }
  }
  else
  {
	$S_Pro=$S_Pro.",".$Special_Projects[$i];
	}
	}
	 }
if($New_Lab_Type!=""&&$Lab_Type!="Select One")
	{
$_SESSION['error']="Please select or type the lab's type!";
	}
	else if($New_Lab_Category!=""&&$Lab_Category!="Select One")
	{
$_SESSION['error']="Please select or type the lab's type!";
	}
	else
	{
	if($New_Lab_Type!="")
	{
	$Lab_Type=$New_Lab_Type;
	}
	if($New_Lab_Category!="")
	{
	$Lab_Category=$New_Lab_Category;
	}
$Lab_Id=$_POST['Lab_Id'];
$SchName=$_POST['SchName'];
        $Tp_Number=$_POST['Tp_Number'];
    $Account_Number=$_POST['Account_Number'];
$Date_of_commencement=$_POST['Date_of_commencement'];
	$Availability_Of_LAN=$_POST['Availability_Of_LAN'];
   $LAN_Supplier=$_POST['LAN_Supplier'];
 $Source_Of_Power=$_POST['Source_Of_Power'];
    $Supplied_Date=$_POST['Supplied_Date'];
   $Speed_Of_WAN=$_POST['Speed_Of_WAN'];
   $Wired_Date=$_POST['Wired_Date'];
   $WAN_Connection_Type=$_POST['WAN_Connection_Type'];
	$Internet_Facilities=$_POST['Internet_Facilities'];
	$name=explode(",",$SchName);
    $nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
if($Lab_Category!=""&&$Lab_Type!=""&&$Lab_Id!=""&&$SchName!=""&&$Source_Of_Power!=""&&$Tp_Number!=""&&$Availability_Of_LAN!=""&&$Date_of_commencement!=""&&$Internet_Facilities!="")
	{
	if($S_Proje=="yes")
  {
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
	  if($spe_other!="")
  {
$sqllab=mysql_query("INSERT INTO lab(Lab_Category,Special_Project,Lab_Id,Lab_Type,School_Id,Source_Of_Power,Tp_Number,Account_Number,Date_of_commencement,Last_Updated_Date)values('$Lab_Category','$S_Pro','$Lab_Id','$Lab_Type','$School_Id','$Source_Of_Power','$Tp_Number','$Account_Number','$Date_of_commencement','$t_d')");
}
else
 {
  $_SESSION['error']="Please type the other special project!<br/>";
 }
}
else
{
$sqllab=mysql_query("INSERT INTO lab(Lab_Category,Special_Project,Lab_Id,Lab_Type,School_Id,Source_Of_Power,Tp_Number,Account_Number,Date_of_commencement,Last_Updated_Date)values('$Lab_Category','$S_Pro','$Lab_Id','$Lab_Type','$School_Id','$Source_Of_Power','$Tp_Number','$Account_Number','$Date_of_commencement','$t_d')");
}
if($sqllab)
  {
$_SESSION['error']="This record is successfully registered!";
$_SESSION['OK']="OK";
$_SESSION['Lab_Id']=$Lab_Id;
$_SESSION['School_Id']=$School_Id;
if($Availability_Of_LAN==""||$LAN_Supplier==""||$Speed_Of_WAN==""||$Supplied_Date==""||$WAN_Connection_Type==""||$Wired_Date=="")
  {
 $_SESSION['errorin']="Some of the network details of this Lab are empty!";
    }
	else
	{
$sqlnet=mysql_query("INSERT INTO network(Lab_Id,School_Id,Availability_Of_LAN,LAN_Supplier,Speed_Of_WAN,Supplied_Date,WAN_Connection_Type,Wired_Date,Internet_Facilities,Last_Updated_Date)values('$Lab_Id','$School_Id','$Availability_Of_LAN','$LAN_Supplier','$Speed_Of_WAN','$Supplied_Date','$WAN_Connection_Type','$Wired_Date','$Internet_Facilities','$t_d')");
  }
  }
else if(!$sqllab&&$sqlnet)
  {
$_SESSION['error']="Sorry unable to register the Lab's basic details but the network details are regisreted!";
  }
  
  else if(!$sqlnet&&$sqllab)
  {
$_SESSION['error']="Sorry unable to register the network details but the basic details are regisreted!";
  }
  else if(!$sqlnet&&!$sqllab)
  {
  $_SESSION['error']="Sorry unable to register this record!";

  }
  }
 else if($Lab_Type==""||$Lab_Id==""||$SchName==""||$Source_Of_Power==""||$Tp_Number==""||$Availability_Of_LAN==""||$Date_of_commencement==""||$Internet_Facilities=="")
	{
	$_SESSION['errorin']="Basic details of the Lab are obivious!";
  }
  }
?>

